#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
using namespace std;

// 打开文件,如果文件不存在,则创建文件
int _open(const char *pathname = "my.txt", int flags = O_RDWR | O_CREAT, mode_t mode = 0777)
{
    return open(pathname, flags, mode);
}

// 读取文件内容
int _read(int fd, void *buf, long count = 1024)
{
    return read(fd, buf, count);
}

// 写入文件内容
int _write(int fd, const void *buf = "hello", long count = 5)
{
    return write(fd, buf, count);
}

int main()
{
    int fd = _open();
    char buf[1024] = {0};
    
    _write(fd);
    // 光标移动到文件开头
    lseek(fd, 0, SEEK_SET);
    _read(fd, buf);
    cout << "read content: " << buf << endl;

    // _open("my.txt", O_RDWR);
    return 0;
}